unit Budgets;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
  cxStyles, dxSkinsCore, dxSkinBlack, dxSkinBlue, dxSkinCaramel, dxSkinCoffee,
  dxSkinDarkRoom, dxSkinDarkSide, dxSkinFoggy, dxSkinGlassOceans,
  dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky,
  dxSkinMcSkin, dxSkinMoneyTwins, dxSkinOffice2007Black, dxSkinOffice2007Blue,
  dxSkinOffice2007Green, dxSkinOffice2007Pink, dxSkinOffice2007Silver,
  dxSkinOffice2010Black, dxSkinOffice2010Blue, dxSkinOffice2010Silver,
  dxSkinPumpkin, dxSkinSeven, dxSkinSharp, dxSkinSilver, dxSkinSpringTime,
  dxSkinStardust, dxSkinSummer2008, dxSkinsDefaultPainters, dxSkinValentine,
  dxSkinXmas2008Blue, dxSkinscxPCPainter, cxCustomData, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, cxGridLevel, cxClasses, cxGridCustomView,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGrid, ADODB,
  dxLayoutContainer, dxLayoutControl, ImgList, cxPropertiesStore,
  dxSkinsdxStatusBarPainter, dxRibbonSkins, dxSkinsdxBarPainter, dxBar,
  dxRibbon, dxStatusBar, dxSkinsdxNavBarPainter, cxTL, cxTextEdit,
  cxTLdxBarBuiltInMenu, dxSkinsdxDockControlPainter, cxPC, dxDockControl,
  dxDockPanel, cxInplaceContainer, dxNavBarCollns, dxNavBarBase, dxNavBar,
  ToolWin, ActnMan, ActnCtrls, cxSplitter, ExtCtrls, Buttons, StdCtrls,
  cxContainer, Menus, cxButtons, cxSpinEdit, cxSpinButton, cxMaskEdit,
  cxButtonEdit;

type CreateOptionsBudgets = record
  FormCaption: string;
end;

type
  TBudgetsForm = class(TForm)
    BudgetsQ: TADOQuery;
    BudgetsDS: TDataSource;
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    Panel5: TPanel;
    cxGrid1: TcxGrid;
    cxGrid1DBTableView1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    LeftSplitter: TcxSplitter;
    btnIncreaseFont: TcxButton;
    btnDecreaseFont: TcxButton;
    btnColumnAutoWidth: TcxButton;
    btnWordWrap: TcxButton;
    btnRightColumnToggle: TcxButton;
    btnAddRecord: TcxButton;
    btnLeftColumnToggle: TcxButton;
    ContractsDS: TDataSource;
    ContractsQ: TADOQuery;
    cxGrid3DBTableView1: TcxGridDBTableView;
    cxGrid3Level1: TcxGridLevel;
    cxGrid3: TcxGrid;
    PropertiesStore: TcxPropertiesStore;
    ContractName: TcxGridDBColumn;
    ContractCode: TcxGridDBColumn;
    BudgetName: TcxGridDBColumn;
    Version: TcxGridDBColumn;
    DateChange: TcxGridDBColumn;
    UsernameChange: TcxGridDBColumn;
    ID: TcxGridDBColumn;
    procedure btnColumnAutoWidthClick(Sender: TObject);
    procedure btnDecreaseFontClick(Sender: TObject);
    procedure btnIncreaseFontClick(Sender: TObject);
    procedure btnWordWrapClick(Sender: TObject);
    procedure btnRightColumnToggleClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure cxGrid3DBTableView1FocusedRecordChanged(
      Sender: TcxCustomGridTableView; APrevFocusedRecord,
      AFocusedRecord: TcxCustomGridRecord;
      ANewItemRecordFocusingChanged: Boolean);
    procedure BudgetsQBeforePost(DataSet: TDataSet);
  private
  	procedure ChangeFontSize(S:TcxGridTableViewStyles;SizeDifference:integer=0);
    { Private declarations }

  public
    { Public declarations }
  end;

var
  BudgetsForm: TBudgetsForm;
  function ShowBudgets(Options: CreateOptionsBudgets): Integer;

implementation

uses Main;

{$R *.dfm}

function ShowBudgets(Options: CreateOptionsBudgets): Integer;
begin
  Result := -1;
  try
    Application.CreateForm(TBudgetsForm, BudgetsForm);
    BudgetsForm.Caption := Options.FormCaption;
    BudgetsForm.Show;
    Result := 1;
  except
    BudgetsForm.Free;
    BudgetsForm := nil;
  end;
end;

procedure TBudgetsForm.ChangeFontSize(S:TcxGridTableViewStyles ; SizeDifference:integer=0);
     var
    i:integer;
begin


      for i:=0 to S.Count-1 do
      begin
        S.Values[i].Font.size:=S.Values[i].font.size+SizeDifference;
      end;

end;


procedure TBudgetsForm.cxGrid3DBTableView1FocusedRecordChanged(
  Sender: TcxCustomGridTableView; APrevFocusedRecord,
  AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
begin
  if not BudgetsQ.Active then
    begin
      BudgetsQ.SQL.Text := 'exec BudgetsToContractShow :NumbersContactsID';
      BudgetsQ.Parameters.ParamByName('NumbersContactsID').Value := ContractsQ.FieldByName('ID').AsInteger;
      BudgetsQ.Open;
    end else
    begin
      BudgetsQ.Close;
      BudgetsQ.SQL.Text := 'exec BudgetsToContractShow :NumbersContactsID';
      BudgetsQ.Parameters.ParamByName('NumbersContactsID').Value := ContractsQ.FieldByName('ID').AsInteger;
      BudgetsQ.Open;
    end;
end;

procedure TBudgetsForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 PropertiesStore.StoreTo(true);
end;

procedure TBudgetsForm.btnRightColumnToggleClick(Sender: TObject);
begin

 if leftsplitter.State=ssOpened then 
  leftsplitter.CloseSplitter
 else
 	LeftSplitter.OpenSplitter;

end;

procedure TBudgetsForm.btnColumnAutoWidthClick(Sender: TObject);
begin
       cxGrid1DBTableView1.optionsView.ColumnAutoWidth:=not(cxGrid1DBTableView1.optionsView.ColumnAutoWidth);
end;

procedure TBudgetsForm.btnDecreaseFontClick(Sender: TObject);
        var i:integer;
begin
   cxGrid1DBTableView1.BeginUpdate;

   with cxGrid1DBTableView1.Styles do
    begin
     if (content<>nil) then Content.Font.Size:=Content.Font.Size-1;
     if (background<>nil) then background.Font.Size:=background.Font.Size-1;
     if (ContentEven<>nil) then ContentEven.Font.Size:=ContentEven.Font.Size-1;
     if (ContentOdd<>nil) then ContentOdd.Font.Size:=ContentOdd.Font.Size-1;
     if (FilterBox<>nil) then FilterBox.Font.Size:=FilterBox.Font.Size-1;
     if (FilterRowInfotext<>nil) then FilterRowInfotext.Font.Size:=FilterRowInfotext.Font.Size-1;
     if (footer<>nil) then footer.Font.Size:=footer.Font.Size-1;
     if (group<>nil) then group.Font.Size:=group.Font.Size-1;
     if (GroupByBox<>nil) then GroupByBox.Font.Size:=GroupByBox.Font.Size-1;
     if (GroupFooterSortedSummary<>nil) then GroupFooterSortedSummary.Font.Size:=GroupFooterSortedSummary.Font.Size-1;
     if (GroupSortedSummary<>nil) then GroupSortedSummary.Font.Size:=GroupSortedSummary.Font.Size-1;
     if (GroupSummary<>nil) then GroupSummary.Font.Size:=GroupSummary.Font.Size-1;
     if (Header<>nil) then Header.Font.Size:=Header.Font.Size-1;
     if (Inactive<>nil) then Inactive.Font.Size:=Inactive.Font.Size-1;
     if (incSearch<>nil) then incSearch.Font.Size:=incSearch.Font.Size-1;
     if (Indicator<>nil) then Indicator.Font.Size:=Indicator.Font.Size-1;
     if (Navigator<>nil) then Navigator.Font.Size:=Navigator.Font.Size-1;
     if (NewItemRowInfoText<>nil) then NewItemRowInfoText.Font.Size:=NewItemRowInfoText.Font.Size-1;
     if (Preview<>nil) then Preview.Font.Size:=Preview.Font.Size-1;
     if (Selection<>nil) then Selection.Font.Size:=Selection.Font.Size-1;
   
    end;

   cxGrid1DBTableView1.EndUpdate;
end;

procedure TBudgetsForm.btnIncreaseFontClick(Sender: TObject);
begin
   cxGrid1DBTableView1.BeginUpdate;
with cxGrid1DBTableView1.Styles do
    begin
   with cxGrid1DBTableView1.Styles do
    begin
     if (content<>nil) then Content.Font.Size:=Content.Font.Size+1;
     if (background<>nil) then background.Font.Size:=background.Font.Size+1;
     if (ContentEven<>nil) then ContentEven.Font.Size:=ContentEven.Font.Size+1;
     if (ContentOdd<>nil) then ContentOdd.Font.Size:=ContentOdd.Font.Size+1;
     if (FilterBox<>nil) then FilterBox.Font.Size:=FilterBox.Font.Size+1;
     if (FilterRowInfotext<>nil) then FilterRowInfotext.Font.Size:=FilterRowInfotext.Font.Size+1;
     if (footer<>nil) then footer.Font.Size:=footer.Font.Size+1;
     if (group<>nil) then group.Font.Size:=group.Font.Size+1;
     if (GroupByBox<>nil) then GroupByBox.Font.Size:=GroupByBox.Font.Size+1;
     if (GroupFooterSortedSummary<>nil) then GroupFooterSortedSummary.Font.Size:=GroupFooterSortedSummary.Font.Size+1;
     if (GroupSortedSummary<>nil) then GroupSortedSummary.Font.Size:=GroupSortedSummary.Font.Size+1;
     if (GroupSummary<>nil) then GroupSummary.Font.Size:=GroupSummary.Font.Size+1;
     if (Header<>nil) then Header.Font.Size:=Header.Font.Size+1;
     if (Inactive<>nil) then Inactive.Font.Size:=Inactive.Font.Size+1;
     if (incSearch<>nil) then incSearch.Font.Size:=incSearch.Font.Size+1;
     if (Indicator<>nil) then Indicator.Font.Size:=Indicator.Font.Size+1;
     if (Navigator<>nil) then Navigator.Font.Size:=Navigator.Font.Size+1;
     if (NewItemRowInfoText<>nil) then NewItemRowInfoText.Font.Size:=NewItemRowInfoText.Font.Size+1;
     if (Preview<>nil) then Preview.Font.Size:=Preview.Font.Size+1;
     if (Selection<>nil) then Selection.Font.Size:=Selection.Font.Size+1;
   
    end;
   
    end;
   cxGrid1DBTableView1.EndUpdate;
end;

procedure TBudgetsForm.btnWordWrapClick(Sender: TObject);
begin
    cxGrid1DBTableView1.optionsView.CellAutoHeight:=not(cxGrid1DBTableView1.optionsView.CellAutoHeight);
end;

procedure TBudgetsForm.BudgetsQBeforePost(DataSet: TDataSet);
begin
  BudgetsQ.FieldByName('NumbersContractsID').Value := ContractsQ.FieldByName('ID').AsInteger;
end;

end.
